﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using Security.Domain;

namespace Security.View.QuickViews.Reports
{
    [DisplayName("Сотрудник")]
    public class EmployeeQuickReport
    {
        public EmployeeQuickReport(Employee employee)
        {
            Name = employee.Name;
            Lastname = employee.Lastname;
            Patronymic = employee.Patronymic;
            DepartmentName = employee.Department.Name;
            PostName = employee.Post.Name;
            LoginEmployees = employee.LoginEmployees.Select(l => new LoginEmployeeQuickReport(l)).ToArray();
            EmployeePermissions = employee.EmployeePermissions.Select(p => new AssociatedPermissionQuickReport(p)).
                                  Union(employee.Post.PostPermissions.Select(p => new AssociatedPermissionQuickReport(p))).
                                  Distinct().
                                  OrderBy(r => r.PermissionName).
                                  ToArray();
        }

        [DisplayName("Имя")]
        public string Name { get; private set; }
        [DisplayName("Фамилия")]
        public string Lastname { get; private set; }
        [DisplayName("Отчество")]
        public string Patronymic { get; private set; }
        [DisplayName("Отдел")]
        public string DepartmentName { get; private set; }
        [DisplayName("Должность")]
        public string PostName { get; private set; }
        [DisplayName("Имена входа")]
        public ICollection<LoginEmployeeQuickReport> LoginEmployees { get; set; }
        [DisplayName("Разрешения")]
        public ICollection<AssociatedPermissionQuickReport> EmployeePermissions { get; set; }
        [Browsable(false)]
        [DisplayName("Идентификатор")]
        public Guid ID { get; set; }
    }
}
